﻿using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace RoleHelper
{

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void cerrarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void nuevaAventuraToolStripMenuItem_Click(object sender, EventArgs e)
        {
            NuevaAventura NA = new NuevaAventura();
            hayaventura.haventura = true;
            NA.MdiParent = this;
            NA.Show();

        }

        private void unloadToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Program.avent.unload();
            nuevaAventuraToolStripMenuItem.Enabled = true;
        }

        public void disablerenabler(string nombre, bool status)
        {
            switch (nombre)
            {
                case "nueva aventura":
                    nuevaAventuraToolStripMenuItem.Enabled = status;
                    break;
                case "editarSitu":
                    editarSituaciontoolStripMenuItem.Enabled = status;
                    break;
                case "editarNPC":
                    editarNPCToolStripMenuItem.Enabled = status;
                    break;
                case "editarPj":
                    editarPjsToolStripMenuItem.Enabled = status;
                    break;
            }
        }

        private void editarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            editar_situaciones ed = new editar_situaciones();
            ed.MdiParent = this;
            ed.Show();
        }

        private void editarToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            EditNPC edn = new EditNPC();
            edn.MdiParent = this;
            edn.Show();
        }

        private void positioningXpressToolStripMenuItem_Click(object sender, EventArgs e)
        {
            /*PositioningXpress PX = new PositioningXpress();
            PX.MdiParent = this;
            PX.Show();*/
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            toolStripStatusHora.Text = Convert.ToString(System.DateTime.Now);
        }

        public void refreshbarra()
        {
            toolStripStatusLabelAventura.Text = "Aventura cargada: " + Convert.ToString(Program.avent.getNombre());
            toolStripStatusLabelSituaiones.Text = "Situaciones: " + Convert.ToString(Program.avent.getSituacion().Count);
            List <Situacion> situs = Program.avent.getSituacion();
            int contNPC = 0;
            for (int i = 0; i < Program.avent.getSituacion().Count; i++)
            {
                contNPC += situs[i].getNPC().Count;
            }
            toolStripStatusLabelNPC.Text = "NPC's: " + Convert.ToString(contNPC);
            toolStripStatusLabelPersonajes.Text = "Personajes: " + Convert.ToString(Program.avent.getPersonaje().Count);
        }

        public void refrescarbarrabd()
        {
            if (Program.bdatos.getconectado() == true)
            {
                toolStripStatusLabelbd.Text = "Base de datos conectada: " + Program.bdatos.getdatabase();
            }
            else
            {
                toolStripStatusLabelbd.Text = "Base de datos conectada: Ninguna";
            }
        }

        private void editarPjsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            EditPj nuevo = new EditPj();
            nuevo.MdiParent = this;
            nuevo.Show();
        }

        private void clasesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Program.bdatos.getconectado() == false)
            {
                refrescarbarrabd();
                Program.ansia = "clasesToolStripMenuItem_Click";
                dblgin db = new dblgin();
                db.MdiParent = this;
                db.Show();
            }
            else
            {
                Clases cl = new Clases();
                cl.MdiParent = this;
                cl.Show();
            }
        }

        private void habilidadesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Program.bdatos.getconectado() == false)
            {
                Program.ansia = "habilidadesToolStripMenuItem_Click";
                refrescarbarrabd();
                dblgin dbl = new dblgin();
                dbl.MdiParent = this;
                dbl.Show();
            }
            else
            {

                Habilidades H1 = new Habilidades();
                H1.MdiParent = this;
                H1.Show();
            }
        }

        private void valkyrNameGeneratorToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Process proceso = new Process();
            ProcessStartInfo psi = new ProcessStartInfo("Valkyr Name Generator.exe");
            proceso.StartInfo = psi;
            proceso.Start();
        }

        private void armasToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Program.bdatos.getconectado() == false)
            {
                Program.ansia = "armasToolStripMenuItem_Click";
                refrescarbarrabd();
                dblgin db = new dblgin();
                db.MdiParent = this;
                db.Show();
            }
            else
            {
                AgregarArma aa = new AgregarArma();
                aa.MdiParent = this;
                aa.Show();
            }
        }

        public void lanzav()
        {
            switch (Program.ansia)
            {
                case "armasToolStripMenuItem_Click":
                    {
                        this.armasToolStripMenuItem_Click(null, null) ;
                        break;
                    }
                case "habilidadesToolStripMenuItem_Click":
                    {
                        this.habilidadesToolStripMenuItem_Click(null, null);
                        break;
                    }
                case "clasesToolStripMenuItem_Click":
                    {
                        this.clasesToolStripMenuItem_Click(null,null);
                        break;
                    }
            }
        }

        private void Form1_Activated(object sender, EventArgs e)
        {
            if(Program.bdatos.getconectado() == true)
                lanzav();
        }
    }
}
